package cn.kxx.controller;


import cn.kxx.constant.MessageConstant;
import cn.kxx.entity.PageResult;
import cn.kxx.entity.QueryPageBean;
import cn.kxx.entity.Result;
import cn.kxx.pojo.CheckGroup;
import cn.kxx.service.CheckGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "检查组管理模块")
@RestController
@RequestMapping("/checkgroup")
public class CheckGroupController {

    @Reference
    private CheckGroupService checkGroupService;

    /**
     * 添加
     *
     * @param checkitemIds checkitem id
     * @param checkGroup   检查组
     * @return {@link Result}
     */
    @ApiOperation("添加检查组")
    @PutMapping("/add")
    public Result add(Integer[] checkitemIds, @RequestBody CheckGroup checkGroup){

        checkGroupService.add(checkitemIds,checkGroup);
        return new Result(true, MessageConstant.ADD_CHECKGROUP_SUCCESS);
    }

    @ApiModelProperty("分页条件查询检查组")
    @PostMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = checkGroupService.findPage(queryPageBean);
        return pageResult;
    }
    @ApiModelProperty("查询单个检查组")
    @GetMapping("/findById/{id}")
    public Result findById(@PathVariable("id") Integer id){

      CheckGroup checkGroup = checkGroupService.findById(id);
      Result result = new Result(true,MessageConstant.QUERY_CHECKGROUP_SUCCESS,checkGroup);

      return result;
    }
    @ApiModelProperty("查询被选中的检查项")
    @GetMapping("/findCheckItemIdsByCheckGroupId/{id}")
    public Result findCheckItemIdsByCheckGroupId(@PathVariable("id") Integer id){

      List<Integer> list = checkGroupService.findCheckItemIdsByCheckGroupId(id);
      Result result = new Result(true,MessageConstant.QUERY_CHECKITEM_SUCCESS,list);

      return result;
    }
    @ApiModelProperty("编辑体检组")
    @PutMapping("/edit")
    public Result edit(Integer[] checkitemIds,@RequestBody CheckGroup checkGroup){

     checkGroupService.edit(checkitemIds,checkGroup);
     Result result = new Result(true,MessageConstant.EDIT_CHECKGROUP_SUCCESS);

      return result;
    }
    @ApiModelProperty("删除检查组")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Integer id){

        checkGroupService.delete(id);
        Result result = new Result(true,MessageConstant.DELETE_CHECKGROUP_SUCCESS);
      return result;
    }

    @ApiOperation("获取所有检查组")
    @GetMapping("/findAll")
    public Result findAll(){
        List<CheckGroup> checkGroups = checkGroupService.findAll();
        return new Result(true,MessageConstant.QUERY_CHECKGROUP_SUCCESS,checkGroups);
    }

}
